package com.example.app.ui.health;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.app.R;

import java.util.List;
import java.util.Map;

public class HealthMenuAdapter extends BaseAdapter {
    private Context context;
    private List<Map<String, Object>> menuItems;

    public HealthMenuAdapter(Context context, List<Map<String, Object>> menuItems) {
        this.context = context;
        this.menuItems = menuItems;
    }

    @Override
    public int getCount() {
        return menuItems.size();
    }

    @Override
    public Object getItem(int position) {
        return menuItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.menu_item, parent, false);
            holder = new ViewHolder();
            holder.icon = convertView.findViewById(R.id.icon_iv);
            holder.title = convertView.findViewById(R.id.title_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Map<String, Object> item = menuItems.get(position);
        holder.icon.setImageResource((Integer) item.get("icon"));
        holder.title.setText((String) item.get("title"));

        return convertView;
    }

    static class ViewHolder {
        ImageView icon;
        TextView title;
    }
}